<%@page import="com.zx.bean.Message"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link rel="stylesheet"
	href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
<script
	src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>

<style type="text/css">
div.listDiv {
	margin: 20px;
}
</style>
</head>

<body>

	<%
		request.setCharacterEncoding("utf-8");
		Message messageBean = new Message();
		String title = request.getParameter("title");
		title = title.replaceAll("<", "&lt;");
		title = title.replaceAll(">", "&gt;");
		title = title.replaceAll("”", "\"");
		title = title.replaceAll("“", "\"");
		messageBean.setTitle(title);
		String content = request.getParameter("content");
		content = content.replaceAll("<", "&lt;");
		content = content.replaceAll(">", "&gt;");
		content = content.replaceAll("”", "\"");
		content = content.replaceAll("“", "\"");
		messageBean.setContent(content);
		messageBean.setUser((String) session.getAttribute("username"));
		messageBean.setDate(new Date());
		if (application.getAttribute("messageList") == null) {
			application.setAttribute("messageList",
					new LinkedList<Message>());
		}
		List<Message> list = (List<Message>) application
				.getAttribute("messageList");
		list.add(messageBean);
	%>
	<div class="listDiv">
		<div class="list_title">
			<b>留言列表</b>
		</div>
		<div class="content">
			<table class="table table-condensed">
				<thead>
					<tr>
						<th>#</th>
						<th>留言者</th>
						<th>标题</th>
						<th>内容</th>
						<th>时间</th>
					</tr>
				</thead>
				<tbody>
					<%
						for (int i = 0; i < list.size(); i++) {
							Message message = list.get(i);
					%>
					<tr>
						<td><%=i + 1%></td>
						<td><%=message.getUser()%></td>
						<td><%=message.getTitle()%></td>
						<td><%=message.getContent()%></td>
						<td><%=message.getDateStr()%></td>
					</tr>
					<%
						}
					%>

				</tbody>
			</table>
		</div>
	</div>
</body>
</html>
